package concurrency.chapter5;

import java.util.stream.IntStream;

public class ThreadJoin {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            IntStream.range(1, 1000)
                    .forEach(i -> System.out.println(Thread.currentThread().getName() + i));
        });
        Thread t2 = new Thread(() -> {
            IntStream.range(1, 1000)
                    .forEach(i -> System.out.println(Thread.currentThread().getName() + i));
        });
        t1.start();
        //t1.join();//放在这里的话会在t1执行完成后才开始执行t2
        t2.start();
        t1.join();//join要放在start之后，t1执行完成后执行main线程
        t2.join();

        IntStream.range(1, 1000)
                .forEach(i -> System.out.println(Thread.currentThread().getName() + i));

    }
}
